﻿using System;
using System.Collections.Generic;

namespace order
{
    class Order
    {
        public int Id 
        { 
            get; 
            set; 
        }
        public string Client 
        { 
            get; 
            set; 
        }
        public double Money 
        { 
            get; 
            set; 
        }
        public string Date 
        { 
            get; 
            set; 
        }

        public List<OrderDetails> orderDetails = new List<OrderDetails>();
        public int CompareTo(object obj)
        {
            Order a = obj as Order;
            return this.Id.CompareTo(a.Id);
        }
        public override bool Equals(object obj)
        {
            Order a = obj as Order;
            return this.Id == a.Id;
        }

        public override int GetHashCode()
        {
            return Convert.ToInt32(Id);
        }
        public Order(int id, string client, string date)
        {
            this.Id = id;
            this.Client = client;
            this.Date = date;
        }
        public void GetAllPrice()
        {
            double i = 0;
            foreach (OrderDetails a in this.orderDetails)
            {
                i = i + a.getPrice();
            }
            this.Money = i;


        }
        public void AddOrderDetails(string name, int number, double price)
        {
            OrderDetails a = new OrderDetails(name, number, price);
            this.orderDetails.Add(a);
        }
        public void RemoveOrderDetails()
        {
            try
            {
                Console.WriteLine("请输入订单明细序号删除相应订单明细：");
                int a = Convert.ToInt32(Console.ReadLine());
                this.orderDetails.RemoveAt(a);
                Console.WriteLine("删除成功");
                Console.WriteLine("***************************************");
            }
            catch
            {
                Console.WriteLine("输入序号错误");
            }
        }
        public void ShowOrderDetails()
        {
            Console.WriteLine("序号 名称 数量 单价");
            foreach (OrderDetails a in this.orderDetails)
            {
                Console.WriteLine("{0} {1} {2} {3}", this.orderDetails.IndexOf(a), a.Name, a.Number, a.Price);
                Console.WriteLine("***************************************");
            }
        }
    }
}
